package com.gmall.bean;


import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import java.math.BigDecimal;

@Data
@AllArgsConstructor
public class OrderWide {
    //orderInfo字段
    Long order_info_id;//主键id
    String order_no;//订单编号
    String order_name;//订单名称
    BigDecimal order_amount;//订单金额
    BigDecimal pay_amount;//实付金额
    Long user_id;//用户Id
    String user_name;//用户姓名
    String user_mobile;//用户手机号
    Integer pay_type;//支付类型 1：Alipay,2:weixin 3:兑换码
    String pay_time;//支付时间
    Integer order_status;//订单状态 1：未支付 2：已支付 3：已关闭 4：退款中 5：已退款
    String trading_account;//交易账号
    String trading_no;//交易号 支付宝 微信等
    String order_time;//订单下单时间
    String supply_name;//补充姓名
    String supply_mobile;//补充手机号
    String supply_email;//补充邮箱
    String create_time;//订单创建时间
    Integer del_flag;//前台删除标志 0：否 1：是
    String uid;//
    String order_id;//
    String couponId;//优惠券id
    String create_date; // 把其他字段处理得到
    String create_hour;
    Long create_ts;

    //ordergoods字段
    Long order_goods_id;
    //Long user_id;
    //String order_id;
    String goods_id;
    Integer goods_num;
    String order_goods_create_time;
    String goods_name;
    Long goods_spec_id;
    String goods_spec_name;
    Long course_id;
    String stage;
    String goods_info;
    String goods_spec_info;
    String sales_strategy_info;
    String coupon_info;
    String orderId;//补充订单id
    String sourceId;//
    //String ordergoods_create_date; // 把其他字段处理得到
    //String ordergoods_create_hour;
    //Long order_goods_create_ts;

    Integer user_age;
    public OrderWide(OrderInfo orderInfo, OrderGoods orderGoods) {
        mergeOrderInfo(orderInfo);
        mergeOrderGoods(orderGoods);

    }

    private void mergeOrderGoods(OrderGoods orderGoods) {
        if (orderGoods != null){
            this.order_goods_id = orderGoods.id;
            this.goods_id = orderGoods.goods_id;
            this.goods_num = orderGoods.goods_num;
            this.order_goods_create_time = orderGoods.create_time;
            this.goods_name = orderGoods.goods_name;
            this.goods_spec_id = orderGoods.goods_spec_id;
            this.goods_spec_name = orderGoods.goods_spec_name;
            this.course_id = orderGoods.course_id;
            this.stage = orderGoods.stage;
            this.goods_info = orderGoods.goods_info;
            this.goods_spec_info = orderGoods.goods_spec_info;
            this.sales_strategy_info = orderGoods.sales_strategy_info;
            this.coupon_info = orderGoods.coupon_info;
            this.orderId = orderGoods.orderId;
            this.sourceId = orderGoods.sourceId;
        }
    }

    private void mergeOrderInfo(OrderInfo orderInfo) {
        if (orderInfo != null) {
            this.order_info_id = orderInfo.id;
            this.order_id = orderInfo.order_id;
            this.order_no = orderInfo.order_no;
            this.order_name = orderInfo.order_name;
            this.order_amount = orderInfo.order_amount;
            this.pay_amount = orderInfo.pay_amount;
            this.user_id = orderInfo.user_id;
            this.user_name = orderInfo.user_name;
            this.user_mobile = orderInfo.user_mobile;
            this.pay_type = orderInfo.pay_type;
            this.pay_time = orderInfo.pay_time;
            this.order_status = orderInfo.order_status;
            this.trading_account = orderInfo.trading_account;
            this.trading_no = orderInfo.trading_no;
            this.order_time = orderInfo.order_time;
            this.supply_name = orderInfo.supply_name;
            this.supply_email = orderInfo.supply_email;
            this.create_time = orderInfo.create_time;
            this.del_flag = orderInfo.del_flag;
            this.uid = orderInfo.uid;
            this.couponId = orderInfo.couponId;
            this.create_date = orderInfo.create_date;
            this.create_hour = orderInfo.create_hour;
            this.create_ts = orderInfo.create_ts;
        }
    }
    public void mergeOtherOrderWide(OrderWide otherOrderWide){
        this.order_status = ObjectUtils.firstNonNull(this.order_status,otherOrderWide.order_status);
        this.create_time = ObjectUtils.firstNonNull(this.create_time,otherOrderWide.create_time);
        this.create_date = ObjectUtils.firstNonNull(this.create_date,otherOrderWide.create_date);
        this.user_id = ObjectUtils.firstNonNull(this.user_id,otherOrderWide.user_id);
        this.order_amount = ObjectUtils.firstNonNull(this.order_amount,otherOrderWide.order_amount);
        this.pay_amount = ObjectUtils.firstNonNull(this.order_amount,otherOrderWide.pay_amount);
        this.couponId = ObjectUtils.firstNonNull(this.couponId,otherOrderWide.couponId);
        this.coupon_info = ObjectUtils.firstNonNull(this.coupon_info,otherOrderWide.coupon_info);
    }

}
